package ranking;

import java.util.Comparator;

public class Opponent extends Player {
  
  private String tournament;
  private String score;
  private boolean isWO = false;
  
  public boolean isWO() {
    return isWO;
  }
  public void setWO(boolean isWO) {
    this.isWO = isWO;
    
    recalculateScore();
  }
  public String getTournament() {
    return tournament;
  }
  public void setTournament(String tournament) {
    this.tournament = tournament;
  }
  public String getScore() {
    return score;
  }
  public void setScore(String score) {
    this.score = score;
  }
  
  
  public void buildPlayer(String ranking, String name, String firstname, String tournament, String socre, boolean isWO) {
    super.buildPlayer(ranking, tournament, firstname);
    setTournament(tournament);
    setScore(socre);
    setWO(isWO);
  }
  
  private void recalculateScore() {
    if (isWO) {
      setScore(null);
    }
  }

  public static final Comparator<Opponent> OPPONENT_COMPARATOR = new Comparator<Opponent>() {
    
    @Override
    public int compare(Opponent opponent1, Opponent opponent2) {
      if (opponent1.getRankPosition() == opponent2.getRankPosition()) {
        return opponent1.getName().compareTo(opponent2.getName());
      } else if (opponent1.getRankPosition() > opponent2.getRankPosition()) {
        return -1;
      } else {
        return 1;
      }
    }
  };
}
